<?php
/**
 * @fileoverview    封装个人信息名片模块数据
 * @author          huhong
 * @date            2012.02.14
 * @copyright       sina meila
 * @param           $uid              发布宝贝用户uid
 * @param           $visiter_uid      访问者uid
 * @return             $data
 */


class ml_biz_user_getinfo {

    private $uid;
    private $vuid;
    private $_ordsCount;//@todo以后改成单例就不用这么麻烦啦
    private $_oAccount;
    private $_oBrief;
    private $_oUserfeed;
    private $_oFollow;
    private $_oFan;
    private $_oNick;
    private $data = array();
    static $_instance;

    private function __construct(){
        $this->_oAccount = new ml_model_dbUserAccount();//@todo以后改成单例就不用这么麻烦啦
        $this->_ordsCount= new ml_model_rdsCount();
        $this->_oNick=new ml_model_rdsHash();
        $this->_oBrief = new ml_model_dbUserBriefInfo();
        $this->_oUserfeed = new ml_model_dbUserfeed();
        $this->_oFollow = new ml_model_dbFollow();
        $this->_oFan = new ml_model_dbFans();
    }

    public function get_type(){
        $this->_ordsCount->getShopType($this->uid);
        $this->data['user_type'] = $this->_ordsCount->get_data();
    }

    public static function get_instance()
    {
        if (is_a(self::$_instance , __CLASS__)) {
            return $this->_instance;
        }
        else
        return new ml_biz_user_getinfo();
    }

    public function initUser($uid, $vuid = null) {
        $this->uid = $uid;
        $this->vuid = $vuid;
        $this->data = array();
         
    }


    public function getUserNick() {
        if (!empty($this->data['nickname'])) return ;
        $this->data['nickname']=Tool_string::un_html($this->_oNick->getNickByUid($this->uid));
    }

    public function getUserStat()
    {
        $rs = $this->_ordsCount->getUserStat(array($this->uid));
        $this->data['contentCount'] = $rs[$this->uid]['content_cnt'];
        $this->data['FollowCount'] = $rs[$this->uid]['follow_cnt'];
        $this->data['fansCount'] = $rs[$this->uid]['fans_cnt'];
        return true;
    }

    
    public function getDecAndTags(){
        $this->_oBrief->getDecAndTagsByUid($this->uid);
        $decAndTags= $this->_oBrief->get_data();
        //$this->data['skill_tags'] = array_unique($decAndTags['skill_tags']);
        $this->data['declaration'] = $decAndTags['declaration'];
    }

    public function getUserSkillTags($ifurl = true){
        $this->_oBrief->getSkillTags($this->uid);
        $tags = $this->_oBrief->get_data();
        $tags['skill_tags']=array_unique($tags['skill_tags']);
        $this->data['skill_tags'] = array();
        if(empty($tags['skill_tags'][0])) return;
        if ($ifurl) {
            foreach ($tags['skill_tags'] as $key=>$tag){
                $this->data['skill_tags'][$key]['tag'] = $tag;
                $this->data['skill_tags'][$key]['url'] = ml_tool_urlMaker::searchTag($tag);
            }
        } else {
            $this->data['skill_tags'] = $tags['skill_tags'];
        }
    }
    public function getUserDeclaration(){
        $this->_oBrief->getDeclarationByUid($this->uid);
        $this->data['declaration']=$this->_oBrief->get_data();
        $this->data['declaration'] = $this->data['declaration']['declaration'];
    }

    public function getUserHeaderUrl($size = 'big'){
        $this->data['HeaderUrl']=ml_tool_picid::uid2portrait($this->uid,$size);
    }

    public function getIsFollow(){
        $this->_oFollow->isFollow($this->vuid,$this->uid);
        $rs=$this->_oFollow->get_data();
        $this->data['isFollow']=$rs ? true : false;
    }

    public function getIsFan(){
        $this->_oFan->isFan($this->vuid,$this->uid);
        $rs=$this->_oFan->get_data();
        $this->data['isFans']=$rs ? true : false;
    }

    public function getUserStatus(){
        $this->_oAccount->getAccountById($this->uid);
        $a = $this->_oAccount->get_data();
        $this->data['verify_email'] = $a['verify_email'];
        $this->data['status'] = $a['status'];
    }

    public function getUserCard() {
        $this->data['owner_uid']=$this->uid;
        $this->getUserNick();
        $this->getUserHeaderUrl('100');
        $this->getUserContentCount();
        $this->getUserStat();
        $this->getIsFollow();
        $result = $this->data;
         
        return $result;
    }

    /**
     * 从不返回失败
     * Enter description here ...
     */
    public function getUserArea(){
        $this->data['owner_uid']=$this->uid;
        $this->getUserNick();
        $this->getUserStat();
        $this->getUserHeaderUrl('big');
         
        $this->data['ifme']=false;
        if($this->vuid==$this->uid){
            $this->data['ifme']=true;
        }
        if (!empty($this->vuid) && $this->uid != $this->vuid) {
            $this->getIsFollow();
            $this->getIsFan();
        }

        $result = $this->data;
         
        return $result;
         
    }

    public function get_result(){
        return $this->data;
    }
}







